# -*- coding:utf-8 -*-
import pymongo
import sys
import mysqldb
import mongoDB

day = sys.argv[1]

#newCar = "http%3A%2F%2Fhjk.m.autohome.com.cn%2Fws%2FInterim%2FIndex%3Fbid%3D0%26levels%3D%26price%3D0%2C0%26pvareaid%3D1001182"
#newCarDb = "new_car_stat"
newCar = "http%3A%2F%2Fydh5.iseber.com%2F"
newCarDb = "weizhang_stat"

collections = "dmarket_access_log"
collection = mongoDB.connMongo(collections)

ret = collection.find({"day": day})
try:
    for item in ret:
        if (item.has_key('u')):
            url = item['u']
            imei = ''
            if (item.has_key('imei')):
                imei = item['imei']
            statTime = item['day']
            system = 0
            if item.has_key('system'):
                if ('android' == item['system'].lower()):
                    system = 1
                else:
                    system = 2
            if (url == newCar):
                mysqldb.inserData(newCarDb, imei, system, statTime)
            else:
                continue
        else:
            continue
except Exception, e:
    print Exception, ":", e

